package com.example.oneservice.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.example.dubbo.dto.ProductDto;
import com.example.dubbo.service.ProductServiceApi;
import com.example.oneservice.domain.User;
import com.example.oneservice.mapper.UserMapper;
import com.example.oneservice.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LXG
 * @since 2021-05-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Reference
    ProductServiceApi productServiceApi;
    @Autowired
    private UserMapper userMapper;

    @Override
    @GlobalTransactional(timeoutMills = 300000, name = "dubbo-gts-seata-example")
    public void addUser(User user) {
        ProductDto product = new ProductDto();
        product.setId(2);
        product.setName("2");
        product.setNum(2);
        productServiceApi.insert(product);
        userMapper.insert(user);
    }
}
